<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>

    <meta charset="UTF-8">
    <title>物资入库</title>
    <script th:src="@{/js/jquery.min.js}"></script>
    <script>
        function queryMsg() {
            var trayCode = document.getElementById("trayCode").value;

            if (trayCode == "" || trayCode == null) {
                alert("托盘条码不能为空！");
                return;
            }

            $.post("/rf/listByTray", {
                trayCode: trayCode
            }, function (result) {

                var data=[];
                data.push(result.data);

                if (data!= null) {
                    var str = "";
                        for (var i = 0; i < data.length; i++) {

                            if(!existProduct(data[i].label_NO)) {
                            str = "<tr><td><input name='checkB' type='checkbox' style='width:25px;height: 25px;' id='checkB' checked hidden></td><td>" + data[i][0].productId + "</td><td>" + data[i][0].productName + "</td><td>" + data[i][0].lotNo + "</td><td>"
                                + data[i][0].quantity + "</td><td hidden>" + data[i][0].label_NO + "</td></tr>";
                            $("#detailMsg1").append(str);
                        }
                    }
                     document.getElementById("productCode").value = "";
                } else {
                    alert("条码信息不存在，请核对！");
                }
            }, "json");

        }
        function existProduct(id)
        {
            var rows = document.getElementsByName("checkB");
            for (var i = 0; i < rows.length; i++) {
                var selectRow = document.getElementById("detailMsg1").rows[i + 1];
                if (selectRow.cells[7].innerHTML == id)
                    return true;
            }
            return  false;
        }
function saveInJob() {
    //控制按钮多次点击
    var btn = document.getElementById('btn_submit');//首先需要获取的是哪一个按钮的id

    btn.disabled = 'disabled';//只要点击就将按钮的可点击的状态更改为不可以点击的状态
    setTimeout(function(){//设置时间，多久可以改变状态为可以点击
        btn.disabled = '';
    },3000);


    var trayCode=document.getElementById("trayCode").value;
    if(trayCode==""){
        alert("托盘码不能为空");
        document.getElementById("trayCode").focus();
        return;
    }
     var entranceId=document.getElementById("entranceId").value;
    if(entranceId==""){
        alert("入口不能为空");
        return;
    }

    $.post("/rf/saveJob", {
        trayCode: trayCode
    }, function (result) {
        alert(result.v_resutmsg)
    }, "json");

}
    </script>
</head>
<body>
<table id="tbb" width="98%" border="1" align="center" cellPadding="0" cellSpacing="0">

    <tr>
        <td align="center">托盘编码:</td>
        <td><input id="trayCode" type="text" name="trayCode"  style="width: 100%"/>


            <button id="btn" type="button" onclick="queryMsg()" style="width: 20%">查询</button> </td>

    </tr>
    <tr>
        <td align="left" colspan="2">
            <table id="detailMsg1" name="detailMsg1">
                <tbody>
                <tr>
                    <td>  </td>
                    <td>物资编码</td>
                    <td>物资名称</td>
                    <td>批号</td>
                    <td>数量</td>
<!--                    <td>重量</td>-->
<!--                    <td>生产日期</td>-->
                    <td hidden>物资唯一码</td>
                </tr>
                </tbody>
            </table>
        </td>
    </tr>

    <tr>
        <td align="right">入口：</td>
        <td><select id="entranceId">
            <option value=""></option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            <option value="6">6</option>
        </select></td>
    </tr>
    <tr>
        <td height="25" bgcolor="#d9e8fc" align="center" colSpan="2">
            <table width="100%">
                <tr>

                    <td width="40%" align="center">
                        <button id="btn_submit" type="button" onclick="saveInJob()" style="width:30%">提交</button>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
</body>
</html>